package com.suprema.biomini;

import com.sun.jna.Pointer;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.ptr.IntByReference;

/**
 * 封裝 SFR300.dll API
 * @author Kent Yeh
 */
public interface SFR300 extends StdCallLibrary {

    /**
     * Size of template.
     */
    public static int SF_TEMPLATESIZE = 384;

    /**
     * The SF_Initialize function initializes the fingerprint reader. At first, SFR300 ver.2 scanner is
     *  searched. If it fails, SFR200 scanner is searched.  
     * @return  設備型號
     */
    DeviceType SF_Initialize();

    /**
     * The SF_Initialize function initializes the fingerprint reader. At first, SFR300 ver.2 scanner is 
     * searched. If it fails, SFR200 scanner is searched.  
     */
    void SF_Uninitialize();

    /**
     * The SF_SetFatMode function is to enable or disable the fast mode. The fast mode is used to 
     * accelerate the speed of 1:N matching in a little sacrifice of recognition accuracy. 
     * @param fastMode SF_NORMAL_MODE : set normal mode (default mode) ,SF_FAST_MODE : set fast mode 
     * @return SF_FAST_MODE : set fast mode 
     */
    int SF_SetFastMode(Boolean fastMode);

    /**
     * The SF_SelectReader function selects the SFR300 ver.2 scanner, SFR300 scanner or SFR200 
     * scanner and initializes the SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. 
     * @param readerType 設備型號
     * @return 設備型號
     */
    DeviceType SF_SelectReader(DeviceType readerType);

    // <editor-fold defaultstate="collapsed" desc="for SFR200.">
    /**
     * The  SF_GetDeviceNumber function returns the number of SFR300 ver.2 scanner, SFR300 
     * scanner or SFR200 scanner attached to the system. 
     * @return Number of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner attached to the system
     */
    int SF_GetDeviceNumber();

    /**
     * The SF_GetDevice function gets index of SFR300 ver.2 scanner, SFR300 scanner or SFR200 
     * scanner which is currently selected. 
     * @return Zero-based index of SFR300 ver2. scanner, SFR300 scanner  or SFR200 scanner which is currently selected. 
     */
    int SF_GetDevice();

    /**
     * The SF_SetDevice function selects SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner.
     * @param device Index of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner being selected. It can 
     * be from 0 to number of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner – 1. 
     * @return Index of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner being selected. It can 
     * be from 0 to number of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner – 1. 
     */
    Boolean SF_SetDevice(int device);

    /**
     * Nonzero if selection of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner succeeds; 
     * otherwise 0. 
     * @param serial 32 bytes-long buffer where serial number is returned. 
     * @return Nonzero if serial number is read successfully; otherwise 0. 
     */
    Boolean SF_GetSerial(byte[] serial);
    // </editor-fold>

    /**
     * The  SF_GetTimeout function gets timeout for SFR300 ver.2 scanner, SFR300 scanner or 
     * SFR200 scanner to wait finger. 
     * @return Timeout value in milli-second 
     */
    int SF_GetTimeout();

    /**
     * The  SF_SetTimeout function sets timeout for SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner to wait finger. 
     * @param timeout Timeout value in milli-second. In case timeout is not needed, it can be 0
     * @return Nonzero if setting of timeout succeeds; otherwise 0. 
     */
    Boolean SF_SetTimeout(int timeout);

    /**
     * The SF_GetBrightness function gets brightness for SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner device. 
     * @return Brightness value which is from 0 to 255. Higher value means darker image. Default value is 100. 
     */
    int SF_GetBrightness();

    /**
     * The SF_SetBrightness function sets brightness for SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. 
     * @param brightness Brightness value which is from 0 to 255. Higher value means darker image. Default value is 100.
     * @return Nonzero if setting of brightness succeeds; otherwise 0. 
     */
    Boolean SF_SetBrightness(int brightness);

    /**
     * The SF_GetSensitivity function gets sensitivity for SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. 
     * @return Sensitivity value which is from 0 to 7. Higher value means more sensitive. Default value is 4.
     */
    int SF_GetSensitivity();

    /**
     * The SF_SetSensitivity function sets sensitivity for SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. 
     * @param sensitivity Sensitivity value which is from 0 to 7. Higher value means more sensitive. Default value is 4. 
     * @return Nonzero if setting of sensitivity succeeds; otherwise 0. 
     */
    Boolean SF_SetSensitivity(int sensitivity);

    /**
     * The SF_IsSensorOn function determines whether a SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner is attached or not. 
     * @return Nonzero if the SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner is attached; otherwise 0. 
     */
    Boolean SF_IsSensorOn();

    /**
     * The  SF_IsFingerOn function determines whether a finger is on the SFR300 ver.2 scanner, 
     * SFR300 scanner or SFR200 scanner or not. 
     * @return Nonzero if a finger is on the SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner; otherwise 0. 
     */
    Boolean SF_IsFingerOn();

    /**
     * The SF_Capture function acquires an image from the SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. 
     * @return Nonzero if the acquisition of an image succeeds; otherwise 0.  
     */
    Boolean SF_Capture();

    /**
     * The SF_AbortCapturing function aborts SFR300 ver.2  scanner, SFR300 scanner or SFR200 scanner to wait for finger. 
     */
    void SF_AbortCapturing();

    /**
     * The SF_GetImageWidth function returns width of fingerprint image. 
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * Before the SF_GetImageWidth function is called, the SF_Capture function should be called to acquire a fingerprint image. 
     * @return Width of fingerprint image.   
     */
    int SF_GetImageWidth();

    /**
     * The SF_GetImageHeight function returns height of fingerprint image. 
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * Before the SF_GetImageHeight function is called, the SF_Capture function should be called to acquire a fingerprint image. 
     * @return Height of fingerprint image.   
     */
    int SF_GetImageHeight();

    /**
     * The SF_GetImageBuffer function returns a pointer to the buffer for fingerprint image. 
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * Before the SF_GetImageBuffer function is called, the SF_Capture function should be called to acquire a fingerprint image. 
     * @return A pointer to the buffer for fingerprint image.   
     */
    Pointer SF_GetImageBuffer();

    /**
     * The SF_Clear function clears the fingerprint image. 
     */
    void SF_Clear();

    /**
     * The SF_Draw function draws the fingerprint image which is acquired using the SF_Capture function. 
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * The core of fingerprint can be drawn in proper position, only after the  SF_Enroll, 
     * SF_EnrollWithVerify, SF_Verify, or SF_Identify function is called.
     * @param hWnd Handle to the window where the fingerprint image is drawn. 
     * @param l Specifies the logical x-coordinate of the upper-left corner of the rectangle. 
     * @param t Specifies the logical y-coordinate of the upper-left corner of the rectangle. 
     * @param r Specifies the logical x-coordinate of the lower-right corner of the rectangle. 
     * @param b Specifies the logical x-coordinate of the lower-right corner of the rectangle. 
     * @param bCore Specifies the logical y-coordinate of the lower-right corner of the rectangle.
     */
    void SF_Draw(HWND hWnd, int l, int t, int r, int b, Boolean bCore);

    /**
     * The SF_Enroll function yields the template of fingerprint from the fingerprint image which is 
     * acquired using the SF_Capture function. 
     * @param template A pointer to the buffer that stores the template of fingerprint. SF_TEMPLATESIZE bytes 
     * should be allocated to this buffer at least. 
     * @param templateSize A pointer to the buffer that stores the template of fingerprint. SF_TEMPLATESIZE bytes 
     * should be allocated to this buffer at least. 
     * @param bCoreDetect Specifies whether the core of fingerprint is detected for enrollment. If  bCoreDetect is 
     * TRUE, the enrollment succeeds only when the core of fingerprint is detected in the center 
     * of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. If bCoreDetect  is FALSE, 
     * the enrollment succeeds as long as the fingerprint image is good enough.
     * @return {@link EnrollType}
     */
    EnrollType SF_Enroll(byte[] template, IntByReference templateSize, Boolean bCoreDetect);

    /**
     * The SF_EnrollWithVerify function yields the template of fingerprint using both the fingerprint 
     * image which is acquired using the  SF_Capture function and the template of fingerprint 
     * enrolled formerly using the SF_Enroll function. 
     * @param template A pointer to the buffer that stores the template of fingerprint. SF_TEMPLATESIZE bytes 
     * should be allocated to this buffer at least. 
     * @param templateSize A pointer to the buffer that stores the template of fingerprint. SF_TEMPLATESIZE bytes 
     * should be allocated to this buffer at least. 
     * @param bCoreDetect Specifies whether the core of fingerprint is detected for enrollment. If  bCoreDetect is 
     * TRUE, the enrollment succeeds only when the core of fingerprint is detected in the center 
     * of SFR300 ver.2 scanner, SFR300 scanner or SFR200 scanner. If bCoreDetect  is FALSE, 
     * the enrollment succeeds as long as the fingerprint image is good enough.
     * @return {@link EnrollType}
     */
    EnrollType SF_EnrollWithVerify(byte[] template, IntByReference templateSize, Boolean bCoreDetect);

    /**
     * The SF_Verify function verifies the fingerprint image acquired using the SF_Capture function 
     * with the template of fingerprint enrolled formerly. 
     * @param template A pointer to the buffer that stores the template of fingerprint enrolled formerly. 
     * @param securityLevel {@link SecurityLevel}
     * @param bCoreDetect Specifies whether the core of fingerprint is detected for verification. If  bCoreDetect  is 
     * TRUE, the verification fails only when the core of fingerprint is not detected in the center 
     * of SFR300 scanner or SFR200 scanner. If bCoreDetect is FALSE, the verification may fail 
     * as long as the fingerprint image is good enough. 
     * @return {@link EnrollType}
     */
    EnrollType SF_Verify(byte[] template, SecurityLevel securityLevel, Boolean bCoreDetect);

    /**
     * The  SF_Identify function identifies the fingerprint image acquired using the  SF_Capture 
     * function with the fingerprint templates enrolled formerly. 
     * @return {@link EnrollType} 
     */
    EnrollType SF_Identify(Pointer template, int count, IntByReference match, SecurityLevel securityLevel, Boolean bCoreDetect, int Timeout);

    /**
     * The  SF_Identify function identifies the fingerprint image acquired using the  SF_Capture 
     * function with the fingerprint templates enrolled formerly. 
     * @return {@link EnrollType} 
     */
    EnrollType SF_IdentifyMT(Pointer template, int count, IntByReference match, SecurityLevel securityLevel, Boolean bCoreDetect, int Timeout);

    /**
     * The SF_GetEnrollQuality function returns quality of processed image.
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * This function returns valid value, only after the SF_Enroll, SF_EnrollWithVerify, SF_Verify,
     * or SF_Identify function is called. 
     * @return Quality value which is from 1 to 100. Typically this value should be above 30 for further 
     * processing such as enroll and matching. Especially in case of enrollment, the use of good 
     * quality image ( above 50 ) is highly recommended. 
     */
    int SF_GetEnrollQuality();

    /**
     * The SF_AbortMatching function aborts matching process of The SF_Identify function. 
     */
    void SF_AbortMatching();

    /**
     * The SF_RotateTemplate function rotates the template of fingerprint enrolled formerly to the 
     * amount of 180 degrees. 
     * <br/><span style="color:red;font-weight:bold">Remarks:</span>
     * The  SF_RotateTemplate function can be used to support 360 degree rotational invariant 
     * matching. The SF_Verify  and SF_Identify  function permits 180 degree ( -90 ~ +90 degree ) 
     * rotation. 
     * @param template A pointer to the buffer that stores the template of fingerprint extracted formerly.   
     */
    void SF_RotateTemplate(byte[] template);
}
